function DragBox(param){
	var that = this;
	var boxId = param.boxId || null;
	var containerId = param.containerId || null;
	var isResize = param.isResize || false;

	if(boxId === null){
		throw "未指定box元素的id";
	}
	if(containerId === null){
		throw "未指定container元素的id";
	}

	var box = document.getElementById(boxId);
	var container = document.getElementById(containerId);

	var containerWidth = container.offsetWidth;
	var containerHeight = container.offsetHeight;

	box.onmousedown = function(ev){
		var ev = ev || window.event;

		var boxLeft = box.offsetLeft;
		var boxTop = box.offsetTop;
		var boxWidth = box.offsetWidth;
		var boxHeight = box.offsetHeight;

		var mouseStartX = ev.clientX;
		var mouseStartY = ev.clientY;

		document.onmousemove = function(ev){
			var ev = ev || window.event;

			var mouseEndX = ev.clientX;
			var mouseEndY = ev.clientY;

			var left = mouseEndX - mouseStartX + boxLeft;
			var top = mouseEndY - mouseStartY + boxTop;
			if(left < 0) left = 0;
			if(left > containerWidth - boxWidth) left = containerWidth - boxWidth;
			if(top < 0) top = 0;
			if(top > containerHeight - boxHeight) top = containerHeight - boxHeight;

			box.style.left = left + 'px';
			box.style.top = top + 'px';
		}
		document.onmouseup = function () {
	        document.onmousemove = null;
	        document.onmouseup = null;
	    }
	}

	//如果要调整大小则执行
	if(isResize){
		var commonStyle = "";
		commonStyle += "position: absolute;background: #fff;cursor: pointer;";
		commonStyle += "width:6px;height:6px;border:1px solid #ccc;border-radius: 6px;";
		var cornerHtml = `
			<div class="corner" style="${commonStyle}left:-3px;top:-3px;"></div>
			<div class="corner" style="${commonStyle}right:-3px;top:-3px;"></div>
			<div class="corner" style="${commonStyle}left:-3px;bottom:-3px;"></div>
			<div class="corner" style="${commonStyle}right:-3px;bottom:-3px;"></div>`;
		$("#" + boxId).append(cornerHtml);

		var cornerLists = box.getElementsByClassName('corner');
		var position = ['leftTop', 'rightTop', 'leftBottom', 'rightBottom'];
		var boxMinWith = 10;
		var boxMinHeight = 10;

		for(var i in cornerLists){
			var corner = cornerLists[i];
			(function(index){
				corner.onmousedown = function(ev){
					var ev = ev || window.event;
					event.stopPropagation();

					var boxLeft = box.offsetLeft;
					var boxTop = box.offsetTop;
					var boxWidth = box.offsetWidth;
					var boxHeight = box.offsetHeight;

					var mouseStartX = ev.clientX;
					var mouseStartY = ev.clientY;

					document.onmousemove = function(ev){
						var ev = ev || window.event;
						var mouseEndX = ev.clientX;
						var mouseEndY = ev.clientY;

						var numX = mouseEndX - mouseStartX;
						var numY = mouseEndY - mouseStartY;
						switch(position[index]){
							case 'leftTop':
								if(boxWidth - numX < boxMinWith) numX = boxWidth - boxMinWith;
								if(boxLeft + numX < 0) numX = 0 - boxLeft;
								if(boxLeft + numX > containerWidth) numX = containerWidth - boxLeft;
								if(boxHeight - numY < boxMinHeight) numY = boxHeight - boxMinHeight;
								if(boxTop + numY < 0) numY = 0 - boxTop;
								if(boxTop + numY > containerHeight) numY = containerHeight - boxTop;

								box.style.left = (boxLeft + numX) + 'px';
								box.style.top = (boxTop + numY) + 'px';
								box.style.width = (boxWidth - numX) + 'px';
								box.style.height = (boxHeight - numY) + 'px';

								break;
							case 'rightTop':
								if(boxLeft + boxWidth + numX > containerWidth) numX = containerWidth - boxLeft -boxWidth;
								if(boxWidth + numX < boxMinWith) numX = boxMinWith - boxWidth;
								if(boxHeight - numY < boxMinHeight) numY = boxHeight - boxMinHeight;
								if(boxTop + numY < 0) numY = 0 - boxTop;

								box.style.top = (boxTop + numY) + 'px';
								box.style.width = (boxWidth + numX) + 'px';
								box.style.height = (boxHeight - numY) + 'px';

								break;
							case 'leftBottom':
								if(boxWidth - numX < boxMinWith) numX = boxWidth - boxMinWith;
								if(boxLeft + numX < 0) numX = 0 - boxLeft;
								if(boxHeight + numY < boxMinHeight) numY = boxMinHeight - boxHeight;
								if(boxTop + boxHeight + numY > containerHeight) numY = containerHeight - boxTop - boxHeight;

								box.style.left = (boxLeft + numX) + 'px';
								box.style.width = (boxWidth - numX) + 'px';
								box.style.height = (boxHeight + numY) + 'px';

								break;
							case 'rightBottom':
								if(boxWidth + numX < boxMinWith) numX = boxMinWith - boxWidth;
								if(boxLeft + boxWidth + numX > containerWidth) numX = containerWidth - boxLeft - boxWidth;
								if(boxHeight + numY < boxMinHeight) numY = boxMinHeight - boxHeight;
								if(boxTop + boxHeight + numY > containerHeight) numY = containerHeight - boxTop - boxHeight;

								box.style.width = (boxWidth + numX) + 'px';
								box.style.height = (boxHeight + numY) + 'px';

								break;
						}
					}
					document.onmouseup = function () {
				        document.onmousemove = null;
				        document.onmouseup = null;
				    }
				}
			})(i)
		}
	}


	that.index = null;
	that.setIndex = function(index){
		that.index = index;
	}
	that.getIndex = function(){
		return that.index;
	}

	that.getData = function(){
		console.log(box);
	}
}